package com.director.core.json.impl.gson;

import com.director.core.DirectMethod;
import com.director.core.DirectTransactionResult;
import com.director.core.ResultWithStrategy;
import com.google.gson.Gson;
import com.google.gson.JsonElement;

/**
 * @author Simone Ricciardi
 * @version 1.0, 11/29/2011
 */
public class GsonTransactionResult implements DirectTransactionResult {

   private JsonElement jsonResult;

   public GsonTransactionResult(Gson gson, DirectMethod directMethod, Object result) {
      Object resultToParse = result;
      if(directMethod.hasReturnDataStrategy()) {
         resultToParse = new ResultWithStrategy(directMethod.getReturnDataStrategy(), result);
      }
      this.jsonResult = gson.toJsonTree(resultToParse);
   }

   public JsonElement getJsonResult() {
      return jsonResult;
   }
}
